﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace Harrby.Command
{
    public static class CommandInvoker
    {
        public static void Invoke(string typeName,string methodName,params object[] parameters)
        {
            Type type = Type.GetType(typeName);
            object o = Activator.CreateInstance(type);
            o.GetType().GetMethod(methodName).Invoke(o,parameters);
        }

        public static void Invoke(Type type, string methodName, params object[] parameters)
        {
            object o = Activator.CreateInstance(type);
            o.GetType().GetMethod(methodName,BindingFlags.Public| BindingFlags.NonPublic| BindingFlags.Instance).Invoke(o,parameters);
        }

        public static void Invoke(string typeName, string methodName, object sender, EventArgs e)
        {
            Type type = Type.GetType(typeName);
            object[] parameters = new object[] { sender, e };
            object o = Activator.CreateInstance(type);
            o.GetType().GetMethod(methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).Invoke(o, parameters);
        }

        public static void Invoke(Type type, string methodName, object sender, EventArgs e)
        {
            object[] parameters = new object[] { sender, e };
            object o = Activator.CreateInstance(type);
            o.GetType().GetMethod(methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).Invoke(o, parameters);
        }
        
    }
}
